Learn R Programming

VeryLargeIntegers (version 0.1.8)

22. Counting the number of primes: Counting the Number of Primes Up to a Given Bound

Description

The function primescount returns the number of primes found up to a given bound. The implemented algorithm uses the Miller-Rabin Primality Test to determine whether a number is prime or not. The number of iterations is configurable, to set the desired accuracy.

Usage

primescount(n, iter = 10, bar = TRUE)

# S3 method for default primescount(n, iter = 10, bar = TRUE)

# S3 method for numeric primescount(n, iter = 10, bar = TRUE)

# S3 method for vli primescount(n, iter = 10, bar = TRUE)

Arguments

n

upper bound of the interval in which we want to count the number of primes; object of class vli or 32 bits integer

iter

number of iterations for each number being tested; numeric

bar

to choose if display or not a progress bar; boolean

Author

Javier Leiva Cuadrado

Examples

Run this code
if (FALSE) {
## Counting primes up to 200
primescount(n = 200, iter = 10, bar = TRUE)

## Computing the approximation of pi(x)
pi(200)

## Showing the numbers by using the Solovay-Strassen test
primes(n = 200, iter = 10, test = "SS", bar = TRUE)
}

Run the code above in your browser using DataLab